#ifndef F_CASSIC_h
#define F_CASSIC_h

// ***********************************************************************

// class EDROOMTopContext

// ***********************************************************************



class EDROOMTopContext {

protected:

enum EDROOMCASSISignal { EDROOMSignalTimeout, EDROOMSignalDestroy, SToListening, SToStandBy, SDataFrame, SSignalFrame, SMsgCommited, SNextSensorSsiDataFrame, STCDataFrame, STCSignalFrame, STMDataFrame, STMSignalFrame };


	friend class CASSI;

	CASSI &EDROOMcomponent;

	CEDROOMMessage * &Msg;

	CEDROOMMessage * &MsgBack;

	//Ports

	CEDROOMInterface & SsiCtrl;
	CEDROOMInterface & Ssi;
	CEDROOMInterface & StoreAndNextFrame;

	enum edroomStateId{I, Listening, DeliveryServer, Standby};

	enum IdTrans{Init, ToListening, ReceiveData, ReceiveData_CrcFail, ReceiveData_IsData, ReceiveData_IsUnidirectional, ReceiveSignal, ReceiveSignal_IsAck, ReceiveSignal_CrcFail, ReceiveSignal_IsDiscovery, MoreData, NoMoreData, ToStandby,  EDROOMMEMORIA };

	//Constantes



	//Variables

	bool_t &VBidirectional;
	bool_t &VCrcOk;
	CDFrame &VDataFrame;
	FrameTypeReceived_t &VFrameType;
	word16_t &VsensorId;
	CDSignal &VSignalFrame;


	//Pool

	class CEDROOMPOOLCDSignal:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLCDSignal(TEDROOMUInt32 elemCount,CDSignal *pMem, TEDROOMBool *pMarks);
		CDSignal	* AllocData();
	};
	CEDROOMPOOLCDSignal	& EDROOMPoolCDSignal;
	class CEDROOMPOOLCDFrame:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLCDFrame(TEDROOMUInt32 elemCount,CDFrame *pMem, TEDROOMBool *pMarks);
		CDFrame	* AllocData();
	};
	CEDROOMPOOLCDFrame	& EDROOMPoolCDFrame;
	class CEDROOMPOOLTEDROOMWord16:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLTEDROOMWord16(TEDROOMUInt32 elemCount,TEDROOMWord16 *pMem, TEDROOMBool *pMarks);
		TEDROOMWord16	* AllocData();
	};
	CEDROOMPOOLTEDROOMWord16	& EDROOMPoolTEDROOMWord16;


	// CONSTRUCTORES

	EDROOMTopContext (CASSI &act, bool_t & EDROOMpVarVBidirectional, bool_t & EDROOMpVarVCrcOk, CDFrame & EDROOMpVarVDataFrame, FrameTypeReceived_t & EDROOMpVarVFrameType, word16_t & EDROOMpVarVsensorId, CDSignal & EDROOMpVarVSignalFrame, CEDROOMPOOLCDSignal & EDROOMpPoolCDSignal, CEDROOMPOOLCDFrame & EDROOMpPoolCDFrame, CEDROOMPOOLTEDROOMWord16 & EDROOMpPoolTEDROOMWord16 );

	EDROOMTopContext ( EDROOMTopContext &contex );

public:

	bool EDROOMSearchContextTrans(TEDROOMTransId &edroomCurrentTrans);

	void EDROOMNuevoMens () { EDROOMcomponent.EDROOMNewMsg(); }

	// Funciones Definidas por el usuario

	void	FDataConfirmed();

	void	FMoreData();

	void	FMsgCommited();

	void	FNoMoreData();

	void	FReceiveData();

	void	FReceiveSignal();

	void	FRequestNextFrame();

	void	FSendFrameUnidirectional();

	void	FSendToStoreFrame();

	void	FToListening();

	bool_t	GIsAck();

	bool_t	GIsData();

	bool_t	GIsDiscovery();

	bool_t	GIsUnidirectional();

};

// ***********************************************************************

// class EDROOMTopState

// ***********************************************************************



class EDROOMTopState : public EDROOMTopContext {

protected:



	EDROOMTopContext::edroomStateId edroomCurrentState;

	EDROOMTopContext::edroomStateId edroomNextState;

	//Variables

	bool_t VBidirectional;
	bool_t VCrcOk;
	CDFrame VDataFrame;
	FrameTypeReceived_t VFrameType;
	word16_t VsensorId;
	CDSignal VSignalFrame;


	//Pools

	CEDROOMPOOLCDSignal	EDROOMPoolCDSignal;
	CEDROOMPOOLCDFrame	EDROOMPoolCDFrame;
	CEDROOMPOOLTEDROOMWord16	EDROOMPoolTEDROOMWord16;


public:

	// CONSTRUCTOR

	EDROOMTopState (CASSI &act, CEDROOMMemory *pEDROOMMemory  );


	// EDROOMBehaviour**********************************************

	void EDROOMBehaviour();

	// Inicio**********************************************

	void EDROOMInicio();

	// ***********************************************************************

	// SubEstado Inicial 

	// ***********************************************************************



	TEDROOMTransId EDROOMIllegada();

	// ***********************************************************************

	// SubEstado Hoja Listening

	// ***********************************************************************



	TEDROOMTransId EDROOMListeningllegada();

	// ***********************************************************************

	// SubEstado Hoja DeliveryServer

	// ***********************************************************************



	TEDROOMTransId EDROOMDeliveryServerllegada();

	// ***********************************************************************

	// SubEstado Hoja Standby

	// ***********************************************************************



	TEDROOMTransId EDROOMStandbyllegada();

};


#endif
